#include <iostream>
#include <windows.h>

int mode, score, base_score;
const int lengthofside=29;

void setColor(WORD color) {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, color);
}


void gotoxy(int y, int x) {
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

bool readMaxScore(const char* filename, int& maxScore) {
    FILE* file = nullptr;
    errno_t err = fopen_s(&file, filename, "r");

    if (err != 0 || file == nullptr) {
        maxScore = 0;
        return false;
    }

    int result = fscanf_s(file, "%d", &maxScore);
    fclose(file);

    if (result != 1) {
        maxScore = 0;
        return false;
    }

    return true;
}

bool writeMaxScore(const char* filename, int score) {
    FILE* file = nullptr;
    errno_t err = fopen_s(&file, filename, "w");

    if (err != 0 || file == nullptr) {
        return false;
    }

    int result = fprintf_s(file, "%d", score);
    fclose(file);

    return result > 0;
}
